package de.backtomedieval.scenarios;

import java.util.ArrayList;
import java.util.Random;

import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import de.backtomedieval.R;
import de.backtomedieval.units.UnitOrder;
import de.backtomedieval.units.UnitSet;
import de.backtomedieval.activities.gamemenu.FightScreen;
import de.backtomedieval.buildings.AbstractBuilding;
import de.backtomedieval.game.City;
import de.backtomedieval.game.Fight;
import de.backtomedieval.game.KI;
import de.backtomedieval.game.Player;
import de.backtomedieval.main.Game;

public class BackToRoots extends AbstractScenario {

	private UnitSet enemy = new UnitSet(null);
	private Random rnd = new Random();
	private int attacksInRound = 500;
	
	
	
	public BackToRoots() {
		super();
		attacksInRound = rnd.nextInt(300)+500;
	}
	
	public UnitSet getEnemy() {
		return enemy;
	}

	public void setEnemy(UnitSet enemy) {
		this.enemy = enemy;
	}

	@Override
	public String getDescription() {
		return "";
	}

	@Override
	public boolean checkScenarioGameTimeout(long round) {
		return false;
	}

	@Override
	public boolean checkWinConditions(Game g) {
	/*	if (attacksInRound==0) {
			Log.v("FIGHT","STARTING THE FIGHT!!");
			UnitSet enemy = Game.getGame().getPlayers().get(1).getCurrentCity().getUnits();
			//Game.getGame().getPlayers().get(1).getCurrentCity().setUnits(new UnitSet());
			UnitSet player = Game.getGame().getcCity().getUnits();
			Fight fight = new Fight(player,enemy,Fight.PLAYER_DEFENDS,Game.getGame().getcCity());
			Fight.addFight(fight);
			fight.setFinalFight(false);
			Activity last = Game.getLastActivity();
			Intent viewUnitsIntent = new Intent(last,
					FightScreen.class);
			last.startActivity(viewUnitsIntent);
			attacksInRound = rnd.nextInt(500)+300;
		} else {
			attacksInRound--;
		} */
		return false;
	}

	@Override
	public String getName() {
		// TODO Auto-generated method stub
		return "Back to roots";
	}

	@Override
	public int getID() {
		// TODO Auto-generated method stub
		return 8;
	}

	public void onStartFight() {}
	
	@Override
	public void atGamestart() {
		City c = Game.getGame().getcCity();
		ArrayList<AbstractBuilding> buildings = c.getBuildings();
		buildings.remove(c.getOre_mine());
		buildings.remove(c.getManufacture());
		buildings.remove(c.getAcademy());
		buildings.remove(c.getTimber_yard());
		c.getTimber_yard().setLevel(20);
		
		Player p = new Player("KI");
		p.addCity("Hamburg");
		p.setKI(new KI(p, Game.getDifficulty()));
		Game.getGame().addPlayer(p);
	}

}
